﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CDSB.Indicators.Model;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using CDSB.Indicators.Enum;

namespace CDSB.Indicators.Communication.Translator
{
    public static class TFSWorkItemToCDSBTaskDesenv
    {
        public static CDSBTaskDesenv TranlateToCDSBTaskDesenv(this WorkItem wItem)
        {
            CDSBTaskDesenv TaskDesenv = new CDSBTaskDesenv();

            TaskDesenv.ID = wItem.Id;
            TaskDesenv.Project = wItem.Project.Name;
            TaskDesenv.State = wItem.State;
            TaskDesenv.Title = wItem.Title;
            TaskDesenv.EstimatedFinishDate = wItem.Fields["Finish Date"].Value != null ? (DateTime)wItem.Fields["Finish Date"].Value : DateTime.MinValue;
            TaskDesenv.EstimatedStartDate = wItem.Fields["Start Date"].Value != null ? (DateTime)wItem.Fields["Start Date"].Value : DateTime.MinValue;
            TaskDesenv.RealizedStartDate = wItem.Fields["Inicio Realizado"].Value != null ? (DateTime)wItem.Fields["Start Date"].Value : DateTime.MinValue;
            TaskDesenv.RealizedFinishDate = wItem.Fields["Termino Realizado"].Value != null ? (DateTime)wItem.Fields["Termino Realizado"].Value : DateTime.MinValue;
            TaskDesenv.Area = wItem.AreaPath;
            TaskDesenv.CodeProvider = wItem.Fields["Bovespa.SINACOR.LocalDevelopment"].Value.ToString();
            
            return TaskDesenv;
        }
    }
}
